package com.battle.service.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.battle.pojo.entity.ApplicationFeedback;
import com.battle.pojo.param.applicationFeedback.*;
import com.battle.pojo.vo.applicationFeedback.*;
import com.battle.pojo.dto.applicationFeedback.*;
import com.battle.service.repository.in.ApplicationFeedbackRepository;
import com.battle.service.service.in.ApplicationFeedbackService;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.utils.ids.IdGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

/**
 * 【描 述】：应用反馈服务
 * 【环 境】：J2SE 17
 * 【详 细】：
 */
@Service
public class ApplicationFeedbackServiceImpl implements ApplicationFeedbackService {

    private final ApplicationFeedbackRepository applicationFeedbackRepository;

    public ApplicationFeedbackServiceImpl(ApplicationFeedbackRepository applicationFeedbackRepository) {
        this.applicationFeedbackRepository = applicationFeedbackRepository;
    }


    /**
     * 创建应用反馈
     *
     * @param param
     */
    @Override
    public void createApplicationFeedback(CreateApplicationFeedbackParam param) {
        ApplicationFeedback applicationFeedback = new ApplicationFeedback();
        BeanUtils.copyProperties(param, applicationFeedback);
        Long id = IdGenerator.SNOW.generate();
        applicationFeedback.setId(id);
        applicationFeedbackRepository.create(applicationFeedback);
    }

    /**
     * 修改应用反馈
     *
     * @param param
     */
    @Override
    public void editApplicationFeedback(EditApplicationFeedbackParam param) {
        Long id = param.getId();
        ApplicationFeedback applicationFeedback = applicationFeedbackRepository.getByIdCheck(id);
        BeanUtils.copyProperties(param, applicationFeedback);
        applicationFeedbackRepository.edit(applicationFeedback);
    }

    /**
     * 移除应用反馈
     *
     * @param id
     */
    @Override
    public void removeApplicationFeedback(Long id) {
        applicationFeedbackRepository.removeById(id);
    }

    /**
     * 启动/禁用应用反馈
     *
     * @param id
     */
    @Override
    public void enabledApplicationFeedback(Long id) {
        ApplicationFeedback applicationFeedback = applicationFeedbackRepository.getByIdCheck(id);
        applicationFeedback.setIsDisable(!applicationFeedback.getIsDisable());
        applicationFeedbackRepository.edit(applicationFeedback);
    }

    /**
     * 获取应用反馈详情
     *
     * @param id
     * @return
     */
    @Override
    public GetApplicationFeedbackVo getApplicationFeedback(Long id) {
        ApplicationFeedback applicationFeedback = applicationFeedbackRepository.getByIdCheck(id);
        GetApplicationFeedbackVo vo = new GetApplicationFeedbackVo();
        BeanUtils.copyProperties(applicationFeedback, vo);
        return vo;
    }


    /**
     * 获取应用反馈下拉列表
     *
     * @param param
     * @return
     */
    @Override
    public List<GetApplicationFeedbackDownListVo> getApplicationFeedbackDownList(GetApplicationFeedbackDownListParam param) {
        ApplicationFeedback po = new ApplicationFeedback();
        if (param != null) {
            BeanUtils.copyProperties(param, po);
        }
        List<ApplicationFeedback> applicationFeedbackList = applicationFeedbackRepository.getListByEntity(po);

        List<GetApplicationFeedbackDownListVo> list = new ArrayList<>();
        for (ApplicationFeedback applicationFeedback : applicationFeedbackList) {
            GetApplicationFeedbackDownListVo vo = new GetApplicationFeedbackDownListVo();
            BeanUtils.copyProperties(applicationFeedback, vo);
            list.add(vo);
        }
        return list;
    }


}



